﻿Imports ControleMatricula.Negocio

Public Class FrmLogin
    Dim db As New DataClassesDataContext()
    Dim RowFuncionario As SPFuncionarioConsultarResult
    Private Sub btnEntrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEntrar.Click

        Dim Retorno As New List(Of SPFuncionarioConsultarResult)
        Retorno = db.SPFuncionarioConsultar(0, txtLogin.Text).ToList()

        If Not (Trim(txtLogin.Text) = "" AndAlso Trim(txtSenha.Text) = "") Then
            If Retorno.Count = 0 Then
                MsgBox("Usuário não cadastrado!", MsgBoxStyle.Information)
                txtLogin.Focus()
                Exit Sub
            ElseIf Retorno.Count > 0 Then
                If Not Retorno(0).STAtivo Then
                    MsgBox("Usuário não está Ativo!", MsgBoxStyle.Information)
                    txtLogin.Focus()
                    Exit Sub
                ElseIf Not txtSenha.Text = Retorno(0).Senha Then
                    MsgBox("Senha digitada está incorreta!", MsgBoxStyle.Information)
                    txtSenha.Focus()
                    Exit Sub
                End If
            End If
        Else
            MsgBox("Obrigatório preenchimento de Login e Senha!", MsgBoxStyle.Information)
            txtLogin.Focus()
            Exit Sub
        End If

        GlobalLogin = Retorno(0).IDFuncionario


        If Not Retorno(0).STProfessor Then
            MDIRibbonControle.MnuDiversos.Visible = False
            MDIRibbonControle.TabFinanceiro.Visible = False
        Else
            MDIRibbonControle.MnuDiversos.Visible = True
            MDIRibbonControle.TabFinanceiro.Visible = True
        End If

        MDIRibbonControle.Opacity = 100
        Me.Close()
    End Sub

    Private Sub btnSair_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSair.Click
        Application.Exit()
    End Sub

    Private Sub txtLogin_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtLogin.KeyDown
        If e.KeyData = Keys.Enter Then
            Call btnEntrar_Click(sender, e)
        End If
    End Sub

    Private Sub txtSenha_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSenha.KeyDown
        If e.KeyData = Keys.Enter Then
            Call btnEntrar_Click(sender, e)
        End If
    End Sub

    Private Sub FrmLogin_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyData = Keys.Enter Then
            Call btnEntrar_Click(sender, e)
        End If
    End Sub
End Class